﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using AutoMapper;
using sharp_net.Repositories;
using zkdao.Enum;

namespace zkdao.Domain {

    public class Rebate : DomainGuid, IAggregateRoot {

        public decimal HandPrice { get; set; }

        public Guid PosterID { get; set; }

        [Required]
        [MaxLength(200)]
        public string Title { get; set; }

        public string ContentRich { get; set; }

        [MaxLength(200)]
        public string LinkUrl { get; set; }

        public DateTime? StartTime { get; set; }
        public DateTime? EndTime { get; set; }

        public int Grade { get; set; }

        public string PhotoPath { get; set; }

        //collection to collection
        public virtual ICollection<Tag> Tags { get; set; }

        public void Update(RebateData data) {
            if (!string.IsNullOrEmpty(data.Title))
                this.Title = data.Title;
            if (!string.IsNullOrEmpty(data.ContentRich))
                this.ContentRich = data.ContentRich;
            if (data.EndTime.HasValue)
                this.EndTime = data.EndTime;
            if (data.StartTime.HasValue)
                this.EndTime = data.StartTime;
            if (!string.IsNullOrEmpty(data.LinkUrl))
                this.LinkUrl = data.LinkUrl;
            if (data.Grade != 0)
                this.Grade = data.Grade;
            if (data.ActEnum != 0)
                this.ActEnum = data.ActEnum;
            if (data.Tags != null && data.Tags.Count != 0) {
                if (Tags == null)
                    Tags = new List<Tag>();
                foreach (var item in data.Tags) {
                    this.Tags.Add(Mapper.Map<TagData, Tag>(item));
                }
            }
        }
    }

    public class RebateData : DomainGuidData {

        public decimal HandPrice { get; set; }

        public string PosterID { get; set; }

        public string Title { get; set; }

        public string ContentRich { get; set; }

        public string LinkUrl { get; set; }

        public DateTime? StartTime { get; set; }

        public DateTime? EndTime { get; set; }

        public int Grade { get; set; }

        public string PhotoPath { get; set; }

        //collection to collection
        public virtual ICollection<TagData> Tags { get; set; }
    }
}